﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace Lottery.Client.SL.Controls
{
    public partial class OnlineStatusControl : UserControl
    {
        public static readonly DependencyProperty OnlineStatusProperty;

        static OnlineStatusControl()
        {
            OnlineStatusProperty = DependencyProperty.Register("OnlineStatus", typeof (short),
                                                               typeof (OnlineStatusControl),
                                                               new PropertyMetadata(PropertyChangedCallback));
        }

        public OnlineStatusControl()
        {
            InitializeComponent();
        }

        public short OnlineStatus
        {
            get { return (short) base.GetValue(OnlineStatusProperty); }
            set { base.SetValue(OnlineStatusProperty, value); }
        }

        private static void PropertyChangedCallback(DependencyObject dependencyObject,
                                                    DependencyPropertyChangedEventArgs
                                                        dependencyPropertyChangedEventArgs)
        {
            var onlineStatusControl = dependencyObject as OnlineStatusControl;
            onlineStatusControl.SetOnlineStatus((short) dependencyPropertyChangedEventArgs.NewValue);
        }

        public void SetOnlineStatus(short onlinestatus)
        {
            if (onlinestatus == 1)
            {
                LightGradientStop.Color = (Color.FromArgb(255, 0, 255, 0));
                InGradientStop.Color = (Colors.Green);
                Storyboard_Light.Begin();
                return;
            }
            LightGradientStop.Color = (Colors.White);
            InGradientStop.Color = (Colors.Gray);
            Storyboard_Light.Stop();
        }
    }
}